#pragma once
#include "Dshow.h"
#include <initguid.h>
#include "atlbase.h"
#include "miifilter.h"

typedef void (*dx_video_cb_type)(Int8 *pBuffer, UInt32 pts, Int32 width, Int32 height, Int32 size);
typedef void (*dx_audio_cb_type)(Int8 *pBuffer, UInt32 pts, Int32 size, Int32 sample_rate, Int32 ch, Int32 sb);


class CMonitorGraph
{
public:
	CMonitorGraph(dx_video_cb_type video_cb, dx_audio_cb_type audio_cb);
	virtual ~CMonitorGraph(void);
public:
	BOOL StartShow(void);
	BOOL StopShow(void);
protected:
	BOOL AddCaptureFilter(void);
	BOOL AddMiiShowFilter(void);
	bool RemoveMiiShowFilter(void);
	bool RemoveCaptureFilter(void);
	void AddMp3PlayFilter(void);
	void RemoveMp3PlayFilter(void);
	HRESULT FindConnectedPin(IBaseFilter* pBF,IPin** ppPin);
	HRESULT RemoveFilter(IGraphBuilder * inGraph, IBaseFilter * inFilter);

	BOOL SetVideoResolution(SIZE *pSize);

    CComPtr<IGraphBuilder> m_pGraphBuilder;
	CComPtr<ICaptureGraphBuilder2>  m_pCaptureBuilder;

	CComPtr<IBaseFilter> m_pVideoCaptureFilter;
	CComPtr<IPin> m_pVideoCapturePinOutput;
	CComPtr<IPin> m_pAudioSourcePinOutput;

	CComPtr<IBaseFilter> m_pMiiShowFilter;
	CComPtr<IPin> m_pMiiShowPinInput;
	CComPtr<IPin> m_pMiiShowPinInputAudio;

	CMiiFilter * m_Show; //CMiiFilter
    CCritSec m_csLock;
	AM_MEDIA_TYPE *m_pVideoType;
	SIZE m_cap_size;
};
